package com.a100.equipment.listener;

import com.a100.equipment.entity.EquArchives;
import com.a100.equipment.entity.vo.ArchivesExcelWriteVo;
import com.a100.equipment.service.EquArchivesService;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import org.springframework.beans.BeanUtils;

import java.util.Map;

public class ArchivesExcelListener extends AnalysisEventListener<ArchivesExcelWriteVo> {
    //注入service方便操作
    private EquArchivesService equArchivesService;
    public ArchivesExcelListener(EquArchivesService equArchivesService){
        this.equArchivesService=equArchivesService;
    }
    //读取excel表头信息
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        System.out.println("表头信息："+headMap);
    }
    //一行一行去读取excle内容
    @Override
    public void invoke(ArchivesExcelWriteVo archivesExcelWriteVo, AnalysisContext analysisContext) {
        //写入数据库
        EquArchives equArchives = new EquArchives();
        BeanUtils.copyProperties(archivesExcelWriteVo,equArchives);
        this.equArchivesService.save(equArchives);
    }
    //读取完成后执行
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
